package com.qtjf.qtmoneyservice.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.qtjf.qtmoneyservice.MyApplication;
import com.qtjf.qtmoneyservice.R;
import com.qtjf.qtmoneyservice.constantSet.Constant;

import java.util.HashMap;
import java.util.Map;

public class XueXinActivity extends BaseActivity {

    ImageView mBack;
    EditText zhangHaoText;
    EditText passwordText;
    TextView submitBt;
    RadioButton radioButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xue_xin);
        super.setTranslucent();

        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mBack = (ImageView) findViewById(R.id.back_bt);
        zhangHaoText= (EditText) findViewById(R.id.zhanghao_text);
        passwordText= (EditText) findViewById(R.id.password_text);
        submitBt= (TextView) findViewById(R.id.submit_bt);
        radioButton= (RadioButton) findViewById(R.id.checkbox);
    }

    private void initData() {
    }

    private void initEvent() {
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                XueXinActivity.this.finish();
            }
        });

        submitBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(radioButton.isChecked()) {
                    submitInfo();
                }else
                {
                    Toast.makeText(XueXinActivity.this,"请同意相关协议",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

//POST 开发完成 http://118.89.185.176:8082/tanzhi/sumbitChsi
    private void submitInfo() {
        String url= Constant.HOMEADDRESS + "tanzhi/sumbitChsi";
        final StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                // TODO Auto-generated method stub
                Toast.makeText(XueXinActivity.this, "提交成功", Toast.LENGTH_SHORT).show();
                if(response.length()>10) {
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                // TODO Auto-generated method stub
                Toast.makeText(XueXinActivity.this, "请检查网络", Toast.LENGTH_SHORT).show();
            }

        }) {
            // 需要重写获取参数的函数,可以向服务器提交参数
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("userId","1");
                map.put("chsiCode",zhangHaoText.getText().toString());
                map.put("chsiPass",passwordText.getText().toString());
                map.put("authCode","");//ziNvText.getText().toString()需要后台改成String
                return map;
            }

        };


        MyApplication.getQueue().add(stringRequest);

    }
}
